<template>
  <div>
    <div v-if="listLoad && couponList.length"
         class="coupon-list"
         :class="{'total-qty': item.stock_qty === '0'}"
         @click="getCoupon(item.is_receive, item.id, index, item.stock_qty)"
         v-for="(item, index) in couponList"
         :key="index">
      <div class="car-img">
        <div class="img">
          <figure>
            <img :src="item.product_image"
                 alt="">
          </figure>
        </div>
        <p class="title"
           v-if="item.stock_qty !== '0'">{{item.receive_num}}人已领取</p>
      </div>
      <div class="text">
        <div class="title"
             v-if="item.total_qty > 0">
          <b>限量{{item.total_qty}}台</b>
        </div>
        <div class="title"
             v-else>
          <b>{{item.preferential_type === '1'?item.denominations+'元':item.discount / 10 + '折'}}</b>
          <span>{{item.preferential_type === '1'?'现金优惠':'现金折扣'}}</span>
        </div>
        <div class="desc">{{item.brand_name}}{{item.product_name}}</div>
        <div class="date">{{item.valid_start_time ? item.valid_start_time.split(' ')[0] : ''}}-{{item.valid_end_time ? item.valid_end_time.split(' ')[0] : ''}}</div>
      </div>
      <div v-if="Number(item.stock_qty) === 0"
           class="active qty"><span>已领完</span></div>
      <div v-if="Number(item.is_receive) === 0 && Number(item.stock_qty) !== 0"
           class="active can-use"><span>立即领取</span></div>
      <div v-if="Number(item.is_receive) !== 0 && Number(item.stock_qty) !== 0"
           class="active have-use"><span>已领取</span></div>
    </div>
    <div class="load-end"
         v-if="listLoad && couponList.length && noMore">
      <span>暂无更多内容</span>
    </div>
    <more-loading v-if="moreLoading"></more-loading>
    <page-loading v-if="!listLoad"></page-loading>
    <empty v-if="!couponList.length"
           tip="还没有优惠券~"></empty>
  </div>
</template>
<script>
import Empty from './Empty'
import MoreLoading from '../plugins/loading/moreLoading'
import PageLoading from '../plugins/loading/pageLoading'
export default {
  props: {
    couponList: {
      type: Array
    },
    noMore: {
      type: Boolean
    },
    moreLoading: {
      type: Boolean
    },
    listLoad: {
      type: Boolean
    }
  },
  components: {
    MoreLoading,
    PageLoading,
    Empty
  },
  mounted () {
    console.log(this.couponList)
  },
  methods: {
    getCoupon (status, id, index, qty) {
      this.$emit('getCoupon', status, id, index, qty)
    }
  }
}
</script>
<style lang="less" scoped>
.coupon-list {
  margin-bottom: 32px;
  width: 100%;
  height: 208px;
  background: #fff;
  box-shadow: 0px 0px 24px 0px rgba(0, 0, 0, 0.08);
  border-radius: 16px;
  display: flex;
  align-items: center;
  position: relative;
  .car-img {
    margin-left: 20px;
    margin-right: 16px;
    .img {
      width: 192px;
      height: 128px;
      position: relative;
      display: flex;
      flex-direction: column;
      border-radius: 12px;
      overflow: hidden;
      figure {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        z-index: 0;
        &::before {
          content: "";
          width: 100%;
          height: 100%;
          background: #efefef
            url()
            no-repeat 50% 50%;
          position: absolute;
          left: 0;
          top: 0;
          text-align: center;
          z-index: -1;
        }
      }
      img {
        width: 100%;
        height: 100%;
        object-fit: cover;
        vertical-align: middle;
      }
    }
    .title {
      margin-top: 12px;
      width: 192px;
      color: rgba(3, 16, 42, 0.6);
      line-height: 32px;
      font-size: 20px;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
      text-align: center;
    }
  }
  .text {
    width: 348px;
    height: 100%;
    display: flex;
    align-items: center;
    flex-direction: column;
    .title {
      margin-top: 28px;
      width: 100%;
      display: flex;
      align-items: baseline;
      color: #fe7e2b;
      font-size: 28px;
      b {
        margin-right: 12px;
        max-width: 80%;
        display: block;
        font-size: 40px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        text-align: center;
        line-height: 52px;
      }
      span {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        text-align: center;
      }
    }
  }
  .active {
    position: absolute;
    top: 0;
    right: 0;
    width: 92px;
    height: 208px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 32px;
    line-height: 36px;
    color: #fff;
    span {
      display: block;
      width: 32px;
      word-break: break-all;
    }
  }
  .can-use {
    background: url(https://s-test.kcimg.cn/m/images/bbs/coupon/coupon_bg.png);
    background-size: 100% 100%;
  }
  .have-use {
    color: rgba(254, 154, 0, 0.4);
    &::before {
      content: "";
      width: 2px;
      height: 208px;
      position: absolute;
      top: 0;
      left: 0;
      background: url(https://s-test.kcimg.cn/m/images/bbs/coupon/coupon_line.png);
      background-size: 100% 100%;
    }
  }
  .qty {
    color: rgba(254, 154, 0);
    &::before {
      content: "";
      width: 2px;
      height: 208px;
      position: absolute;
      top: 0;
      left: 0;
      background: url(https://s-test.kcimg.cn/m/images/bbs/coupon/coupon_line.png);
      background-size: 100% 100%;
    }
  }
  .desc {
    width: 100%;
    margin: 16px 0 20px;
    font-size: 28px;
    color: rgba(3, 16, 42, 0.6);
    line-height: 32px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .date {
    width: 100%;
    font-size: 20px;
    color: rgba(3, 16, 42, 0.6);
    line-height: 32px;
  }
}
.total-qty {
  .text {
    .title {
      color: rgba(254, 126, 43, 0.6);
    }
  }
  .desc {
    color: rgba(3, 16, 42, 0.4);
  }
  .date {
    color: rgba(3, 16, 42, 0.4);
  }
}
.load-end {
  font-size: 24px;
  color: rgba(3, 16, 42, 0.4);
  line-height: 34px;
  display: flex;
  width: 100%;
  padding: 40px 0;
  box-sizing: border-box;
  justify-content: center;
  span {
    margin: 0 10px;
  }
}
</style>
